#!/bin/bash

set -e

VERSION=latest
if [ $# == 1 ] ; then
VERSION=$1
fi

cd ../
./build skipMerge
wait
if [ $? -ne 0 ]; then
    exit $?
fi

cd ./docker

cp ../bin/*.jar ./

IMAGE_NAME="tzfun/etcd-workbench:$VERSION"

echo Building dockerfile $IMAGE_NAME
docker build -f Dockerfile -t $IMAGE_NAME . 
wait
if [ $? -ne 0 ]; then
    exit $?
fi

echo Pushing image $IMAGE_NAME
docker push $IMAGE_NAME
wait
if [ $? -ne 0 ]; then
    exit $?
fi

rm *.jar